import { defineStore } from 'pinia'

import $ajax from '../api/to8050.js'
import { ElMessage, ElMessageBox } from 'element-plus'
export const useGridStore = defineStore('grid', {
  state: () => ({
    /** @type {{ text: string, id: number, isFinished: boolean }[]} */
    grids: [],
    gridvalue: []
  }),
  getters: {
    gridtree(state) {
      return state.grids
    }
  },
  actions: {
    async loaddata() {
      if (this.grids === null || this.grids.length == 0) {
        const path = '/grid/s/all/tree'
        const res = await $ajax.get(path)
        if (res.code === 200) {
          this.grids = res.result.children
          console.log(this.grids)
        }
      }
    }
  }
})
